<template>
  <nav class="navbar">
    <div class="navbar-container">
      <!-- Logo -->
      <div class="navbar-logo">
        <router-link to="/" class="logo-link">
          <img src="@/assets/logo.svg" alt="宠物乐园" class="logo-image" />
          <span class="logo-text">宠物乐园</span>
        </router-link>
      </div>

      <!-- 桌面端导航链接 -->
      <div class="navbar-links">
        <router-link to="/" class="nav-link">首页</router-link>
        <router-link to="/breeds" class="nav-link">宠物品种</router-link>
        <router-link to="/member-center" class="nav-link">会员空间</router-link>
        <router-link to="/pet-knowledge" class="nav-link">宠物知识</router-link>
      </div>

      <!-- 用户操作按钮 -->
      <div class="navbar-actions">
        <router-link to="/login" class="nav-button nav-button-outline">登录</router-link>
        <router-link to="/register" class="nav-button nav-button-primary">注册</router-link>
      </div>

      <!-- 移动端菜单按钮 -->
      <div class="mobile-menu-button" @click="toggleMobileMenu">
        <div class="menu-icon" :class="{ 'menu-open': isMobileMenuOpen }">
          <span></span>
          <span></span>
          <span></span>
        </div>
      </div>
    </div>

    <!-- 移动端导航菜单 -->
    <div class="mobile-menu" :class="{ 'mobile-menu-open': isMobileMenuOpen }">
      <div class="mobile-links">
        <router-link to="/" class="mobile-nav-link" @click="toggleMobileMenu">首页</router-link>
        <router-link to="/breeds" class="mobile-nav-link" @click="toggleMobileMenu">宠物品种</router-link>
        <router-link to="/member-center" class="mobile-nav-link" @click="toggleMobileMenu">会员空间</router-link>
        <router-link to="/pet-knowledge" class="mobile-nav-link" @click="toggleMobileMenu">宠物知识</router-link>
        <router-link to="/login" class="mobile-nav-link" @click="toggleMobileMenu">登录</router-link>
        <router-link to="/register" class="mobile-nav-link" @click="toggleMobileMenu">注册</router-link>
      </div>
    </div>
  </nav>
</template>

<script setup>
import { ref } from 'vue'
import { RouterLink } from 'vue-router'

// 移动端菜单状态
const isMobileMenuOpen = ref(false)

// 切换移动端菜单
const toggleMobileMenu = () => {
  isMobileMenuOpen.value = !isMobileMenuOpen.value
}
</script>

<style scoped>
/* 全局样式变量 */
:root {
  --primary-color: #4CAF50;
  --primary-hover: #3d8b40;
  --text-primary: #333;
  --text-secondary: #666;
  --white: #ffffff;
  --radius: 12px;
  --transition: all 0.3s ease;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* 导航栏样式 */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background-color: var(--white);
  box-shadow: var(--shadow);
  z-index: 100;
  transition: var(--transition);
}

.navbar-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  max-width: 1400px;
  margin: 0 auto;
}

/* Logo 样式 */
.navbar-logo {
  display: flex;
  align-items: center;
}

.logo-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
}

.logo-image {
  height: 40px;
  margin-right: 12px;
}

.logo-text {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-color);
}

/* 导航链接样式 */
.navbar-links {
  display: flex;
  align-items: center;
  gap: 32px;
}

.nav-link {
  text-decoration: none;
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: 600;
  transition: var(--transition);
  position: relative;
}

.nav-link:hover {
  color: var(--primary-color);
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 0;
  height: 2px;
  background-color: var(--primary-color);
  transition: var(--transition);
}

.nav-link:hover::after {
  width: 100%;
}

/* 导航按钮样式 */
.navbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-button {
  padding: 8px 20px;
  border-radius: 25px;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  transition: var(--transition);
  cursor: pointer;
  border: 2px solid transparent;
}

.nav-button-outline {
  color: var(--primary-color);
  border-color: var(--primary-color);
}

.nav-button-outline:hover {
  background-color: var(--primary-color);
  color: var(--white);
}

.nav-button-primary {
  background-color: var(--primary-color);
  color: var(--white);
}

.nav-button-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

/* 移动端菜单按钮 */
.mobile-menu-button {
  display: none;
  cursor: pointer;
  padding: 8px;
}

.menu-icon {
  width: 24px;
  height: 20px;
  position: relative;
}

.menu-icon span {
  position: absolute;
  height: 2px;
  width: 100%;
  background-color: var(--text-primary);
  left: 0;
  transition: var(--transition);
}

.menu-icon span:nth-child(1) {
  top: 0;
}

.menu-icon span:nth-child(2) {
  top: 9px;
}

.menu-icon span:nth-child(3) {
  bottom: 0;
}

.menu-icon.menu-open span:nth-child(1) {
  transform: rotate(45deg);
  top: 9px;
}

.menu-icon.menu-open span:nth-child(2) {
  opacity: 0;
  left: -30px;
}

.menu-icon.menu-open span:nth-child(3) {
  transform: rotate(-45deg);
  bottom: 9px;
}

/* 移动端导航菜单 */
.mobile-menu {
  position: fixed;
  top: 72px;
  left: 0;
  width: 100%;
  background-color: var(--white);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08);
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
  z-index: 99;
}

.mobile-menu.mobile-menu-open {
  max-height: 400px;
}

.mobile-links {
  display: flex;
  flex-direction: column;
  padding: 16px 24px;
}

.mobile-nav-link {
  padding: 16px 0;
  text-decoration: none;
  color: var(--text-primary);
  font-size: 1.1rem;
  font-weight: 600;
  border-bottom: 1px solid #f0f0f0;
  transition: var(--transition);
}

.mobile-nav-link:hover {
  color: var(--primary-color);
  padding-left: 12px;
}

.mobile-nav-link:last-child {
  border-bottom: none;
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .navbar-container {
    padding: 16px 16px;
  }
  
  .navbar-links {
    gap: 24px;
  }
}

@media (max-width: 768px) {
  .navbar-links,
  .navbar-actions {
    display: none;
  }
  
  .mobile-menu-button {
    display: block;
  }
  
  .logo-text {
    font-size: 1.2rem;
  }
}

@media (max-width: 480px) {
  .navbar-container {
    padding: 12px 16px;
  }
  
  .logo-image {
    height: 32px;
    margin-right: 8px;
  }
  
  .logo-text {
    font-size: 1.1rem;
  }
  
  .mobile-menu {
    top: 56px;
  }
}
</style>